package com.example.controller;
import com.example.pojo.Result;
import com.example.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@Slf4j
@RestController
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;
//    private static Logger log = LoggerFactory.getLogger(UploadController.class);
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {//MultipartFile这个api来接收上传过来的文件
       String url = aliOSSUtils.upload(image);//调用阿里云的工具类，将前端传过来的文件储存到阿里云中，返回储存的url，然后再返回给前端，然后展示在页面上
        log.info("文件上传成功，文件访问的url：{}",url);
        return Result.success(url);
    }
}
